<?php
namespace app\common\product\model;

use think\Model;

class ProductDescription extends Model
{
    protected $table = "tk_store_product_description";

    // 关闭自动写入时间戳
    protected $autoWriteTimestamp = false;

    protected $type = [];

    public function setDescriptionAttr($value)
    {
        return empty($value) ? '[]' : json_encode($value);
    }

    public function getDescriptionAttr($value) {
        return empty($value) ? [] : json_decode($value, true);
    }

    public function getDescAttr($value, $data) {
        if (empty($data['description'])) {
            return [];
        }

        $desc = json_decode($data['description'], true);
        return array_column($desc, 'url');
    }
}
